package com.work.cos.web.controller.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.work.cos.domain.entity.CreditsLogEntity;
import com.work.cos.domain.vo.ComServiceResVo;
import com.work.cos.service.interfc.ICreditsLogService;

@RestController
@RequestMapping("/api/credits")
public class CreditsController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(CreditsController.class);
	
	@Autowired
	private ICreditsLogService creditsLogService;
	
	/**
	 * 积分明细查询(云豆)
	 * @param userId
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@PostMapping(value = "/query")
	public ComServiceResVo queryCredits(@RequestParam Long userId,@RequestParam int pageNo,
			@RequestParam int pageSize){
		LOGGER.debug("api credits query ... ");
		return ComServiceResVo.returnList(creditsLogService.
				findCreditsLogByUserId(userId, pageNo, pageSize).getItems());
	}
	
	@PostMapping(value = "/add")
	public ComServiceResVo addCredits(CreditsLogEntity entity) {
		
		boolean flag = creditsLogService.addCreditsLog(entity);
		if(! flag){
			
			return ComServiceResVo.returnErrorMessage("获取奖励失败!");
		}
		return ComServiceResVo.returnSuccessStatus();
	}
}
